import java.util.ArrayList;
import java.util.Collections;
import java.io.*;

/**
 * EBook Organizer
 * 4/30/2010
 * <P>
 * A class that contains all the settings for the <code>EBookOrganizer</code>.
 * </P>
 * @version 0.1
 */
public class Settings implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7503086199401682499L;
	
	ArrayList<FileType> fileTypes = new ArrayList<FileType>();
	String filePath = "saveData.dat";
	
	public Settings() {
		/** ad in default FileTypes */
		fileTypes.add( new FileTypePDF() );
	}
	
	public void addFileType( FileType type) {
		fileTypes.add( type );
		Collections.sort( fileTypes );
	}
	
	public void removeFileType (FileType type) {
		fileTypes.remove( type );
	}
	
	public void setFilePathName(String path) {
		filePath = path;
	}
	
	public FileType getFileType(int index) {
		return fileTypes.get(index);
	}
	
	public boolean containsFileType( FileType type) {
		
		for (int i =0 ; i <fileTypes.size(); i++) {
			if (type.compareTo( fileTypes.get(i) ) ==0 )
				return true;
		}
		
		return false;
	}
	
	public int getNumberOfFileTypes() {
		return fileTypes.size();
	}
	
	public String getFilePath() {
		return filePath;
	}
	
	public FileType isOfType(File file) {
		String path = file.getPath();
		String[] split = path.split("\\.");
		
		String type = "."+split[ split.length-1 ];
		
		for (int i =0; i <fileTypes.size(); i++) {
			FileType fileType = fileTypes.get( i );
			String fType = fileType.getFileType();
			
			if ( fType.equalsIgnoreCase( type) )
				return fileType;
		}
		
		return null;
	}
}
